package eu.chargetime.ocpp.jsonclientimplementation.ocpphandler;

import cn.hutool.json.JSONUtil;
import eu.chargetime.ocpp.feature.profile.ClientCoreEventHandler;
import eu.chargetime.ocpp.model.core.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;

/**
 * 客户端 Event 处理
 */
@TestConfiguration
@Slf4j
public class ClientCoreEventHandlerConfig {

    @Bean
    public ClientCoreEventHandler configTestClient() {
        return new ClientCoreEventHandler() {
            @Override
            public ChangeAvailabilityConfirmation handleChangeAvailabilityRequest(ChangeAvailabilityRequest request) {
                log.info("[handleChangeAvailabilityRequest], begin");
                System.out.println(request);
                // ... handle event
                log.info("[handleChangeAvailabilityRequest], end");
                return new ChangeAvailabilityConfirmation(AvailabilityStatus.Accepted);
            }

            @Override
            public GetConfigurationConfirmation handleGetConfigurationRequest(GetConfigurationRequest request) {
                log.info("[handleGetConfigurationRequest], begin");
                System.out.println(request);
                // ... handle event
                log.info("[handleGetConfigurationRequest], end");
                return null; // returning null means unsupported feature
            }

            @Override
            public ChangeConfigurationConfirmation handleChangeConfigurationRequest(ChangeConfigurationRequest request) {
                log.info("[handleChangeConfigurationRequest], begin");
                System.out.println(request);
                // ... handle event
                log.info("[handleChangeConfigurationRequest], end");
                return null; // returning null means unsupported feature
            }

            @Override
            public ClearCacheConfirmation handleClearCacheRequest(ClearCacheRequest request) {
                log.info("[handleClearCacheRequest], begin");
                System.out.println(request);
                // ... handle event
                log.info("[handleClearCacheRequest], end");
                return null; // returning null means unsupported feature
            }

            @Override
            public DataTransferConfirmation handleDataTransferRequest(DataTransferRequest request) {
                log.info("[handleDataTransferRequest], begin");
                System.out.println(request);
                // ... handle event
                log.info("[handleDataTransferRequest], begin");
                return null; // returning null means unsupported feature
            }

            @Override
            public RemoteStartTransactionConfirmation handleRemoteStartTransactionRequest(RemoteStartTransactionRequest request) {
                log.info("[handleRemoteStartTransactionRequest],开始充电的日志 begin,request:{}",JSONUtil.toJsonStr(request));
                String idTag = request.getIdTag();
                System.out.println(request);
                // ... handle event
                RemoteStartTransactionConfirmation confirmation = new RemoteStartTransactionConfirmation(RemoteStartStopStatus.Accepted);

                log.info("[handleRemoteStartTransactionRequest],开始充电结果返回 end,remoteStartTransactionConfirmation:{} ", JSONUtil.toJsonStr(confirmation));
                return confirmation; // returning null means unsupported feature
            }

            @Override
            public RemoteStopTransactionConfirmation handleRemoteStopTransactionRequest(RemoteStopTransactionRequest request) {
                log.info("[handleRemoteStopTransactionRequest],结束充电日志 begin,request:{}",JSONUtil.toJsonStr(request));
                Integer transactionId = request.getTransactionId();
                System.out.println(request);
                // ... handle event
                RemoteStopTransactionConfirmation confirmation = new RemoteStopTransactionConfirmation(RemoteStartStopStatus.Accepted);
                log.info("[handleRemoteStopTransactionRequest],结束充电日志  end,confirmation:{}",JSONUtil.toJsonStr(confirmation));
                return confirmation; // returning null means unsupported feature
            }

            @Override
            public ResetConfirmation handleResetRequest(ResetRequest request) {
                log.info("[handleResetRequest], begin");
                System.out.println(request);
                // ... handle event
                log.info("[handleResetRequest], begin");
                return null; // returning null means unsupported feature
            }

            @Override
            public UnlockConnectorConfirmation handleUnlockConnectorRequest(UnlockConnectorRequest request) {
                log.info("[handleUnlockConnectorRequest], begin");
                System.out.println(request);
                // ... handle event
                log.info("[handleUnlockConnectorRequest], end");
                return null; // returning null means unsupported feature
            }
        };
    }
}
